#!/bin/bash

load inquirer

help() {
  echo "Usage:"
  echo "  swarm logs <service> [options]"
}

core() {
  local service=$1
  if [ "$service" = "" ]; then
    log::error "service is required"
    exit 1
  fi

  local available_service=($(docker stack services ${service} | grep ${service} | awk '{print $2}'))
  inquirer::select "Select an service ?" available_service select_sub_service

  docker service logs --follow --tail 10 $select_sub_service
}

run() {
  if [ "$1" = "-h" ] || [ "$1" = "--help" ]; then
    help
    exit 0
  fi

  core $@
}

run $@
